// packageA/pages/refound/index.js
const app = getApp();
var utils = require('../../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    current: 0,
    id: [],
    refound_list: [],
    isShow: false
  },

  // 右侧导航
  toggle: function () {
    let that = this;
    that.setData({
      isShow: !that.data.isShow
    })
  },

  cancel: function (e) {
    let that = this;
    let t = wx.getStorageSync("token");
    wx.showModal({
      title: '',
      content: '是否确认取消，取消后无法申请售后哟',
      success(res) {
        if (res.confirm) {
          // console.log('用户点击确定')
          wx.request({
            url: app.apiUrl("refound/cancel"),
            data: {
              ret_id: e.currentTarget.dataset.retid
            },
            header: {
              "Content-Type": "application/json",
              "X-ECTouch-Authorization": t
            },
            method: "POST",
            success: function (res) {
              wx.showToast({
                title: res.data.msg,
                icon: 'none'
              })
              wx.request({
                url: app.apiUrl("refound/relist"),
                data: {
                  order_id: that.data.id,
                  ru_id:app.globalData.ru_id
                },
                header: {
                  "Content-Type": "application/json",
                  "X-ECTouch-Authorization": t
                },
                method: "POST",
                success: function (res) {
                  // console.log(res.data)
                  that.setData({
                    relist: res.data.refound_list
                  })
                }
              });
            }
          });
        } else if (res.cancel) {
          // console.log('用户点击取消')
        }
      }
    })
  },

  bindHeaderTap: function (e) {
    let that = this;
    // console.log(e.target.dataset.index)
    // console.log(that.data.id)
    that.setData({
      current: e.target.dataset.index
    })
    if (e.target.dataset.index == 0) {
      wx.setNavigationBarTitle({
        title: '售后申请'
      })
    } else if (e.target.dataset.index == 1) {
      wx.setNavigationBarTitle({
        title: '进度查询'
      })
      let t = wx.getStorageSync("token");
      wx.request({
        url: app.apiUrl("refound/relist"),
        data: {
          order_id: that.data.id,
          ru_id:app.globalData.ru_id
        },
        header: {
          "Content-Type": "application/json",
          "X-ECTouch-Authorization": t
        },
        method: "POST",
        success: function (res) {
          // console.log(res.data)
          that.setData({
            relist: res.data.refound_list
          })
        }
      });
    }
  },

  //加载列表
  refoundList: function (order_id) {
    let that = this;
    let t = wx.getStorageSync("token");
    wx.request({
      url: app.apiUrl("refound"),
      data: {
        order_id: order_id,
        ru_id:app.globalData.ru_id
      },
      header: {
        "Content-Type": "application/json",
        "X-ECTouch-Authorization": t
      },
      method: "POST",
      success: function (res) {
        // console.log(res.data.order_list)
        that.setData({
          refound_list: res.data.order_list
        })
      }
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    that.setData({
      id: options.id
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    // console.log(that.data.id)
    // console.log(that.data.current)
    that.refoundList(that.data.id);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})